import re
import datetime

from flask import Blueprint, jsonify, request

from app import LogService
from utils import create_response, StateCode

bank_bp = Blueprint('bank_server', __name__)


@bank_bp.route('/bank/card_verify', methods=['POST'])
def bankCardVerify():
    pattern = r'^\d{13,19}$'
    # 确保银行卡号是一个完整的 13 到 19 位的数字字符串
    number = request.json.get('bankCard')
    state = {
        "result": bool(re.match(pattern, number))
    }
    LogService.log()
    return jsonify(create_response(StateCode.SUCCESS, data=state)), 200


@bank_bp.route('/bank/pay', methods=['POST'])
def pay():
    # 模拟支付成功，返回
    state = {"state": "successful", "pay_time": datetime.datetime.now()}
    LogService.log()
    return jsonify(create_response(StateCode.SUCCESS, data=state)), 200


@bank_bp.route('/bank/query', methods=['POST'])
def query():
    # 模拟验证成功，返回
    state = {"state": "successful", "pay_time": datetime.datetime.now()}
    LogService.log()
    return jsonify(create_response(StateCode.SUCCESS, data=state)), 200
